package com.prs.crm.action.oa;

import java.io.InputStream;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

import com.prs.crm.context.ToolKits;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.BusinessTravel;
import com.prs.crm.domain.oa.GoOut;
import com.prs.crm.report.ExportConfig;
import com.prs.crm.report.ReportCell;
import com.prs.crm.report.ReportTable;
import com.prs.crm.service.ReportService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.oa.BusinessTravelService;

public class BusinessTravelAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private InputStream inputStream;
	private String contentType;
	private String outFilePath;
	private String outfileName;
	private int exportType;
	private String accepts;
	private ReportService reportService;
	
	private PersonService personService;
	private BusinessTravel businessTravel;
	private BusinessTravelService businessTravelService;
	
	
	@Action("editBusinessTravel")
	public String editBusinessTravel() {
		
		return SUCCESS;
	}
	@Action("listBusinessTravel")
	public String listBusinessTravel(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				BusinessTravel.class);
		criteria.addOrder(Order.desc("recordTime"));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.businessTravelService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action(value = "saveBusinessTravel", results = {
			@Result(name = "success", type = "redirect", location = "listBusinessTravel"),
			@Result(name = "error", type = "chain", location = "editBusinessTravel") })
	public String saveBusinessTravel() {
		if(businessTravel.getStartTime().after(businessTravel.getEndTime())){
			this.addActionError("开始时间不能在结束时间之后！");
			return ERROR;
		}
			this.businessTravel.setRecordTime2(new Date());
			this.businessTravelService.save(businessTravel);
		return SUCCESS;
	}	
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public InputStream getInputStream() {
		return inputStream;
	}
	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	public String getContentType() {
		return contentType;
	}
	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
	public String getOutFilePath() {
		return outFilePath;
	}
	public void setOutFilePath(String outFilePath) {
		this.outFilePath = outFilePath;
	}
	public String getOutfileName() {
		return outfileName;
	}
	public void setOutfileName(String outfileName) {
		this.outfileName = outfileName;
	}
	public int getExportType() {
		return exportType;
	}
	public void setExportType(int exportType) {
		this.exportType = exportType;
	}
	public String getAccepts() {
		return accepts;
	}
	public void setAccepts(String accepts) {
		this.accepts = accepts;
	}
	public PersonService getPersonService() {
		return personService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public BusinessTravel getBusinessTravel() {
		return businessTravel;
	}
	public void setBusinessTravel(BusinessTravel businessTravel) {
		this.businessTravel = businessTravel;
	}
	public BusinessTravelService getBusinessTravelService() {
		return businessTravelService;
	}
	public void setBusinessTravelService(BusinessTravelService businessTravelService) {
		this.businessTravelService = businessTravelService;
	}
	public ReportService getReportService() {
		return reportService;
	}
	public void setReportService(ReportService reportService) {
		this.reportService = reportService;
	}
	
}
